<extend name="Public/layout"/>
<block name="head">
    <title>登录</title>
    <link rel="stylesheet" href="__PUBLIC__css/login.css">
    <script src="__PUBLIC__assets/better-scroll/bscroll.min.js"></script>
	<style>
		.footer{
			display:none !important;
		}
	</style>
</block>
<block name="main">
    <div class="banner">
        <img src="__PUBLIC__images/register-banner-1.png" alt="">
    </div>

    <div class="form">
        <div class="form-group">
            <input type="text" class="phone-number" placeholder="请输入您的手机号码">
        </div>
        <div class="form-group">
            <input type="password" class="password" placeholder="请输入您的登录密码">
        </div>
    </div>

    <div class="btn-wrapper">
        <a onclick="login()" href="javascript:">登录</a>
        <p class=clearfix>
            <a href="{:U('User/forgot_password')}" class="iforgot">忘记密码</a>
            <a href="{:U('User/register_first')}" class="register-btn">立即注册</a>
        </p>
    </div>

</block>
<block name="js">
    <script type="text/javascript">

        var check = false;
        
        function login() {
            var phone = $('.phone-number').val();
            var password = $('.password').val();
            if (!phone) {
                msg = "请输入手机号码";
                layer.msg(msg)
                check = false;
                return;
            } else {
                if (!(/^1\d{10}$/.test(phone))) {
                    msg = "手机号码格式错误，请重新输入";
                    layer.open({
                        content: msg
                        , skin: 'msg'
                        , time: 1 //2秒后自动关闭
                    });
                    check = false;
                    return;
                } else {
                    if (!password) {
                        layer.open({
                            content: "密码不能为空"
                            , skin: 'msg'
                            , time: 1 //2秒后自动关闭
                        });
                        check = false;
                        return;
                    } else {
                        var password = $.md5(password);
                        check = true;
                        $.post('{:U("User/login")}', {phone: phone, password: password}, function (res) {
                            if (res.err == 0) {
                                layer.open({
                                    content: res.msg
                                    , skin: 'msg'
                                    , time: 1,
                                    end: function () {
                                        var callback = "{$_GET['callback']}";
                                        if (callback) {
                                            if (callback == "/home/user/register") {
                                                location.href = "{:U('Index/index')}"
                                            } else {
                                                location.href = callback;
                                            }
                                        } else {
                                            location.href = "{:U('Index/index')}"
                                        }
                                    }
                                });
                            } else {
                                layer.open({
                                    content: res.msg
                                    , skin: 'msg'
                                    , time: 1 //2秒后自动关闭
                                });
                            }
                        });
                    }
                }
            }
        }


    </script>
</block>